<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\widgets\Datetimepicker;

Datetimepicker::widget(['timepicker' => 'true', 'datepicker' => 'false', 'format' => 'H:i', 'step' => '5']);
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height yx-add-content-box">
    <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false, 'options' => ['class' => 'form-validate']]); ?>
    <table width="100%" class="table-form">
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['name']; ?></th>
            <td><?= $form->field($model, 'name', ['template' => '{input}{hint}{error}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['img']; ?></th>
            <td><?= $form->field($model, 'img', ['template' => '{input}{hint}{error}'])->widget(\doumiaoduo\ueditor\ImageUploadSingle::className(), [
                    'clientOptions' => ['serverUrl' => \common\components\helpers\Fun::url(['/uploader/action']),],
                    'buttonOptions' => ['class' => 'button'],
                ])->hint('此图片优先显示') ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['mobile']; ?></th>
            <td><?= $form->field($model, 'mobile', ['template' => '{input}{hint}{error}'])->textInput(['class' => 'input-text'])->hint('请填写手机号!该手机号将作为账号!') ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['headmaster_account']; ?></th>
            <td><?= $form->field($model, 'headmaster_account', ['template' => '{input}{hint}{error}'])->textInput(['class' => 'input-text', 'readonly' => 'readonly']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['sex']; ?></th>
            <td><?= $form->field($model, 'sex', ['template' => '{input}{hint}{error}'])->radioList(['0' => '女', '1' => '男'], ['prompt' => '请选择分类', 'class' => 'input-dropdownlist']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['age']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'age', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>$year,'options' => ['placeholder' => '请选择']]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['mechanic_id']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'mechanic_id', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>$mechanic,'options' => ['placeholder' => '请选择']]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['cate_id']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'cate_id', ['template' => '{input}{error}{hint}'])->widget(\kartik\select2\Select2::className(),['data'=>[1=>'益智',2=>'音乐',3=>'形体'],'options' => ['placeholder' => '请选择']]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['is_tutor']; ?></th>
            <td><?= $form->field($model, 'is_tutor', ['template' => '{input}{hint}{error}'])->radioList(['0' => '否', '1' => '是'], ['prompt' => '请选择分类', 'class' => 'input-dropdownlist']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['status']; ?></th>
            <td><?= $form->field($model, 'status', ['template' => '{input}{hint}{error}'])->radioList(['0' => '不授课', '1' => '授课'], ['prompt' => '请选择状态', 'class' => 'input-dropdownlist']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['teach_cate']; ?></th>
            <td style="display: inline-block;width: 206px"><?= $form->field($model, 'teach_cate', ['template' => '{input}{hint}{error}'])->widget(\kartik\select2\Select2::className(),['data'=>$cate,'options' => ['placeholder' => '请选择分类','encode'=>false]]) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['teach_cates']; ?></th>
            <td><?= $form->field($model, 'teach_cates[]', ['template' => '{input}{hint}{error}'])->checkboxList($cate_checked, ['class' => 'input-dropdownlist']) ?></td>
        </tr>
        <!--
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['is_teaching_art']; ?></th>
            <td><?= $form->field($model, 'is_teaching_art', ['template' => '{input}{hint}{error}'])->checkbox([], [ 'class' => 'input-dropdownlist']) ?></td>
        </tr>
        -->
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['email']; ?></th>
            <td><?= $form->field($model, 'email', ['template' => '{input}{hint}{error}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['address']; ?></th>
            <td><?= $form->field($model, 'address', ['template' => '{input}{hint}{error}'])->textInput(['class' => 'input-text']) ?></td>
        </tr>
        <tr>
            <th class="zx-goods-table"><?= $model->attributeLabels()['description']; ?></th>
            <td><?= $form->field($model, 'description', ['template' => '{input}{hint}{error}'])->widget(\doumiaoduo\ueditor\Ueditor::className(), ['clientOptions' => [
                    'serverUrl' => \common\components\helpers\Fun::url(['/uploader/action']),
                    'toolbars' => [['fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'simpleupload','removeformat']],
                    'initialFrameWidth' => '60%'
                ],]); ?></td>
        </tr>
    </table>
    <div class="yx-submit-box" style="width: 100%">
        <?= \yii\helpers\Html::submitButton('提交', ['class' => "button yx-submit", 'id' => 'dosubmit']) ?>
    </div>
</div>

<?php \yii\widgets\ActiveForm::end(); ?>
<script>
    $(document).ready(function () {
        //已选择分类复选框全部选中
        var v = $.trim($('input[id="teacher-name"]').val());
        if (!(v == "")) {
            $('#teacher-teach_cates input[type="checkbox"]').each(function () {
                $(this).attr('checked', true);
            });
        }
    });
    //根据所选择机构,确定给机构的班主任
    $('#teacher-mechanic_id').change(function () {
        var mechanic_id = $('#teacher-mechanic_id').val();
        $.ajax({
            url: '/teacher-getheadmaster',
            data: {
                mechanic_id: mechanic_id
            },
            type: 'post',
            cache: false,
            dataType: 'json',
            success: function (data) {
                var headmaster = data.headmaster;
                var str_headmaster = '<option>请选择班主任</option>';
                for (var i = 0; i < headmaster.length; i++) {
                    var data_headmaster = headmaster[i];
                    str_headmaster += '<option value=' + data_headmaster.id + '>' + data_headmaster.name + '</option>';
                }
                $('#teacher-parent_id').html(str_headmaster);
            }
        });
    });
    //选择老师授课分类
    $(function () {
        $('#teacher-teach_cate').change(function () {
            var ids = new Array();
            $('#teacher-teach_cates').each(function () {
                if ($(this).attr('checked') == true) {
                    ids[$(this).val()] = $(this).val();
                }
            });
            id_cate = $('#teacher-teach_cate').val();
            if ($.inArray(id_cate, ids) == -1) {
                str_cate = $('#teacher-teach_cate').find("option:selected").text();
                str_cate = str_cate.replace("├", "");
                str_cate = str_cate.replace("└", "");

                html_cate = "<label><input type='checkbox' name='Teacher[teach_cates][]' checked='checked' value='" + id_cate + "'>" + str_cate + '</label>';
                $('#teacher-teach_cates').append(html_cate);
            }
        });
    });
</script>

